<%--
  Created by IntelliJ IDEA.
  User: CM
  Date: 17/5/12
  Time: 下午10:27
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>

<html>
<head>
    <jsp:include page="../../common/header.jsp"></jsp:include>
    <jsp:include page="../../common/cloud-head.jsp"></jsp:include>
    <jsp:include page="../../common/dt.jsp"></jsp:include>
    <script type="text/javascript" src="${ctx}/resources/pagination/script/jquery.pagination.js"></script>
    <link href="${ctx}/resources/pagination/style/pagination.css" rel="stylesheet" type="text/css">
    <link href="${ctx}/resources/pagination/style/common.css" rel="stylesheet" type="text/css">


    <style>
        .page-content {
            padding: 1rem 2rem;
            overflow: hidden;
            position: relative;
        }

        .info-box {
            min-width: 20rem;
        }

        .info-box img {
            display: inline-block;
            width: 6rem;
            height: 6rem;
            vertical-align: top;
            margin-left: 2rem;
        }

        .info-box .name-box {
            display: inline-block;
            vertical-align: top;
            margin-left: 1rem;
        }

        .name-box p {
            line-height: 3rem;
            margin: 0;
            padding: 0;
        }

        .operator-box {
            min-width: 20rem;
        }

        .operator-box .btn {
            margin: 0 0.8rem;
        }

        .auth-dialog .modal-header {
            padding: 0;
        }

        .auth-dialog .auto-info-box {
            height: 10rem;
            display: block;
            overflow-y: auto;
        }

        .auth-dialog .form-group img {
            display: inline-block;
            width: 8rem !important;
            height: auto;
        }

        .auth-dialog .form-group img:first-child {
            margin-left: 4rem;
        }

        .auth-dialog .modal-content {
            height: 30rem;
        }

        .auth-info-box, .adduser-box {
            height: 20rem;
            max-height: 20rem;
            overflow: auto;
            padding: 3rem 2rem;
        }

        .choose-file {
            position: relative;
            display: inline-block;
            background: #D0EEFF;
            border: 1px solid #99D3F5;
            border-radius: 4px;
            padding: 4px 12px;
            overflow: hidden;
            color: #1E88C7;
            text-decoration: none;
            text-indent: 0;
            line-height: 20px;
        }

        #up-file {
            position: absolute;
            width: 80px;
            /* font-size: 100px; */
            right: 0px;
            top: 0;
            left: 0px;
            opacity: 0;
        }

        .choose-file:hover {
            background: #AADFFD;
            border-color: #78C3F3;
            color: #004974;
            text-decoration: solid;
        }

        .modal .modal-footer {
            border-radius: 0 0 2px 2px;
            background-color: #fafafa;
            padding: 4px 6px;
            height: 56px;
            width: 100%;
        }

        .modal-footer {
            margin-top: 15px;
            padding: 19px 20px 20px;
            text-align: right;
            border-top: 1px solid #e5e5e5;
        }

        .modal-footer button {
            vertical-align: middle;
            display: inline-block;
            margin: 0 0.8rem !important;
            min-width: 6rem;
        }

        .showfilename {
            display: inline-block;
            font-size: 2rem;
            line-height: 3rem;
            vertical-align: top;
        }
        table img.data-preview-img.edit_able {
            margin: 0.2rem 0.4rem;
            width: 8rem;
        }

        span.edit_able {
            cursor: pointer;
            position: relative;
            border-bottom: 1px solid transparent;
        }

        span.edit_able:hover {
            border-bottom-color: #8c8c8c;

        }

        span.edit_able:hover:after {
            content: '\f044';
            font-family: FontAwesome;
            margin-left: 0.5rem;
            color: #0aa;
            text-decoration: none !important;

        }
    </style>
</head>
<body>


<div class="page-content">
    <div class="col-md-12">
        <div class="card">
            <div class="card-action">
                条件查询
            </div>
            <div class="card-content">
                <div class="col-md-12">
                    <div class="form-group normal col-md-3">
                        <label>关键字</label>
                        <input type="text" value="" name="keyword" id="keyword" placeholder="输入姓名或者手机号码过滤"/>
                    </div>
                    <div class="form-group normal col-md-4">
                        <label>注册时间</label>
                        <input type="text" value="" name="timeRange" id="timeRange" placeholder="点击选择"
                               style="width:24rem;"/>
                    </div>
                    <shiro:hasRole name="all">
                        <c:choose>
                            <c:when test="${type == 1 || type == 2}">
                                <div class="form-group normal col-md-3">
                                    <label>关联商户</label>
                                    <select style="display: inline-block;float: none;width:12rem;" id="shopId"
                                            name="shopId">
                                        <option value="" selected>全部</option>
                                        <c:forEach items="${shopUsers}" var="sp">
                                            <option value="${sp.id}">${sp.companyName}</option>
                                        </c:forEach>
                                    </select>
                                </div>
                                <c:if test="${type == 2}">
                                    <div class="form-group col-md-3">
                                        <label>审核状态</label>
                                        <select name="reviewStatus" id="reviewStatus" style="width:10rem;">
                                            <option value="" selected>全部</option>
                                            <option value="0">未提交资料</option>
                                            <option value="1">待审核</option>
                                            <option value="2">审核通过</option>
                                            <option value="3">审核不通过</option>
                                        </select>
                                    </div>
                                </c:if>
                            </c:when>
                            <c:when test="${ type == 3 || type == 4}">
                                <div class="form-group col-md-3">
                                    <label>审核状态</label>
                                    <select name="reviewStatus" id="reviewStatus" style="width:10rem;">
                                        <option value="" selected>全部</option>
                                        <option value="0">未提交资料</option>
                                        <option value="1">待审核</option>
                                        <option value="2">审核通过</option>
                                        <option value="3">审核不通过</option>
                                    </select>
                                </div>
                            </c:when>
                        </c:choose>
                    </shiro:hasRole>
                    <button class="btn btn-primary" onclick="reSearch();">
                        <i class="fa fa-search"></i>查询
                    </button>
                    <button class="btn btn-primary" onclick="addUser();">
                        <i class="fa fa-plus"></i>批量导入
                    </button>
                </div>
                <div class="clear"></div>
            </div>
        </div>

    </div>
    <div class="col-md-12">
        <div class="card">
            <div class="card-content">
                <div class="col-md-12">
                    <table id="mainTable" cellpadding="0" cellspacing="0" border="0" class="auto-table">
                        <thead>
                        <tr>
                            <td>用户信息</td>
                            <td>手机号码</td>
                            <td>注册时间</td>
                            <td>注册类型</td>
                            <td>用户类型</td>
                            <shiro:hasRole name="all">
                                <c:choose>
                                    <c:when test="${type == 1 || type == 2}">
                                        <td>关联商户</td>
                                        <c:if test="${type == 2}">
                                            <td>审核状态</td>
                                            <td>操作</td>
                                        </c:if>
                                    </c:when>
                                    <c:when test="${type == 3 || type == 4}">
                                        <td>审核状态</td>
                                        <td>操作</td>
                                    </c:when>
                                </c:choose>
                            </shiro:hasRole>
                            <%--<td>最后访问时间</td>--%>
                        </tr>
                        </thead>
                        <tbody>
                        </tbody>
                    </table>
                    <input type="hidden" name="pageNum" id="pageNum" value="1"/>
                    <input type="hidden" name="pageSize" id="pageSize" value="10"/>
                    <input type="hidden" name="total" id="total" value=""/>

                    <div class="pagination pagination-right pagination-small" id="pagination">

                    </div>
                </div>
                <div class="clear"></div>
            </div>
        </div>
    </div>

</div>
<div aria-hidden="true" class="modal auth-dialog" style="background: transparent; box-shadow: none">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h4>认证资料</h4>
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true"
                        onclick="$('.auth-dialog').modal('hide')">&times;
                </button>
            </div>
            <div class="auth-info-box">

            </div>
            <%--<div class="modal-footer">--%>
            <%--<div class="col-md-12">--%>
            <%--<div class="col-md-offset-3 col-md-9">--%>
            <%--<a href="javascript:$('.auth-dialog').modal('hide');" class="btn btn-success submitBtn" style="display: none;">--%>
            <%--确定 <i class="fa fa-arrow-circle-right"></i>--%>
            <%--</a>--%>
            <%--</div>--%>
            <%--</div>--%>
            <%--</div>--%>
        </div>

    </div>
</div>
<div aria-hidden="true" class="modal add-user" style="background: transparent; box-shadow: none">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h4>用户信息文件导入</h4>
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true"
                        onclick="$('.add-user').modal('hide')">&times;
                </button>
            </div>
            <div class="adduser-box">
                <%--<form id="form2" method="post" enctype="multipart/form-data" action="${ctx}/common/file/upload/upexcel/${type}"--%>
                <%--enctype="multipart/form-data" style="align: center">--%>
                <h4>选择Excel表：</h4>
                <a href="javascripe" class="choose-file" onclick="getfilename()">选择文件
                    <input type="file" id="up-file" name="file_upload"
                           onchange="uploadUserExcel('up-file',null,'file-path','')"/>
                </a>

                <input type="text" id="file-path" name="file-type"/>
                <div class="showfilename"></div>
                <%--</form>--%>
            </div>

            <%--<div class="modal-footer">--%>
            <%--<div class="col-md-12">--%>
            <%--<div class="col-md-offset-3 col-md-9">--%>
            <%--<a href="javascript:$('.auth-dialog').modal('hide');" class="btn btn-success submitBtn" style="display: none;">--%>
            <%--确定 <i class="fa fa-arrow-circle-right"></i>--%>
            <%--</a>--%>
            <%--</div>--%>
            <%--</div>--%>
            <%--</div>--%>
        </div>

    </div>
</div>
<script type="text/html" id="dataTmpl">
    <tr data-id="\${id}">
        <td>
            <div class="info-box">
                <img src="\${userLogo}" onerror="this.src='${ctx}/resources/portal/img/banner/logo-1.png'"/>
                <div class="name-box">
                    <p><strong>\${userType!= 1?companyName:name}</strong></p>
                    <p>\${remark}</p>
                </div>
            </div>
        </td>
        <td>
            <p class="phone-box">\${phone||'未绑定'}</p>
        </td>
        <td>
            <p class="register-time">
                \${formatDate(regTime)}
            </p>
        </td>
        <td>
            <p class="register-type">
                {{if regType}}
                {{if regType == 'weChatApp'}}
                公众号用户
                {{else regType == 1}}
                安卓用户
                {{else regType == 2}}
                iOS用户
                {{else regType == 3}}
                web用户
                {{/if}}
                {{/if}}
            </p>
        </td>
        <td>
            {{if userType == 1}}
            普通用户
            {{else userType == 2}}
            厂商/供应商
            {{else userType == 3}}
            代理商管理
            {{else userType == 4}}
            辅助料配料商
            {{else userType == 5}}
            物流公司
            {{/if}}
        </td>
        <shiro:hasRole name="all">
            <c:choose>
                <c:when test="${type == 1 || type ==2}">
                    <td>
                        {{if firstShopId}}
                        <p class="shop-user" data-id="\${shopId}"><i class="fa fa-spinner fa-spin"></i>载入中...</p>
                        {{else}}
                        --
                        {{/if}}
                    </td>
                    <c:if test="${type == 2}">
                        <td>
                            {{if reviewStatus == 0}}
                            <p class="review-status" style="color:#666;">未提交资料</p>
                            {{else reviewStatus == 1}}
                            <p class="review-status" style="color:orange;">待审核</p>
                            <a href="javascript:showAuthInfo('\${id}');">查看资料</a>
                            {{else reviewStatus == 2}}
                            <p class="review-status" style="color:green;">审核通过</p>
                            <a href="javascript:showAuthInfo('\${id}');">查看资料</a>
                            {{else reviewStatus == 3}}
                            <p class="review-status" style="color:#a33;">审核不通过</p>
                            <a href="javascript:showAuthInfo('\${id}');">查看资料</a>
                            <p><strong>备注：</strong>\${reviewNote}</p>
                            {{else}}
                            <p class="review-status" style="color:#a33;">未知状态</p>
                            {{/if}}
                        </td>
                    </c:if>
                </c:when>
                <c:when test="${type == 2 || type == 3 || type == 4||type==5}">
                    <td>
                        {{if reviewStatus == 0}}
                        <p class="review-status" style="color:#666;">未提交资料</p>
                        {{else reviewStatus == 1}}
                        <p class="review-status" style="color:orange;">待审核</p>
                        <a href="javascript:showAuthInfo('\${id}');">查看资料</a>
                        {{else reviewStatus == 2}}
                        <p class="review-status" style="color:green;">审核通过</p>
                        <a href="javascript:showAuthInfo('\${id}');">查看资料</a>
                        <p><strong>备注：</strong>\${reviewNotes}</p>
                        {{else reviewStatus == 3}}
                        <p class="review-status" style="color:#a33;">审核不通过</p>
                        <a href="javascript:showAuthInfo('\${id}');">查看资料</a>
                        <p><strong>备注：</strong>\${reviewNotes}</p>
                        {{else}}
                        <p class="review-status" style="color:#a33;">未知状态</p>
                        {{/if}}
                    </td>
                </c:when>
            </c:choose>

            <c:if test="${type == 2 || type == 3 || type == 4||type == 5}">
                <td>
                    {{if reviewStatus == 1}}
                    <div class="operator-box">
                        <button class="btn btn-primary" onclick="review('\${id}',true,${type})">审核通过</button>
                        <button class="btn btn-danger" onclick="review('\${id}',false,${type})">审核不通过</button>
                    </div>
                    {{else reviewStatus == 2}}
                    <div class="operator-box">
                        <button class="btn btn-danger" onclick="review('\${id}',false,${type})">审核不通过</button></div>
                    {{else reviewStatus == 0}}
                    <div>
                        --
                    </div>
                    {{else reviewStatus == 3}}
                    <div class="operator-box">
                        <button class="btn btn-warning" onclick="review('\${id}',true,${type})">重新审核通过</button>
                    </div>
                    {{/if}}
                    <div class="operator-box">
                        <button class="btn btn-warning" onclick="deleteuser('\${id}')">删除用户</button>
                    </div>
                </td>
            </c:if>
        </shiro:hasRole>
        <%--<td>--%>
        <%------%>
        <%--</td>--%>
    </tr>


</script>
<script type="text/html" id="authInfoTmpl">
    <%--{{if real_name}}--%>
    <%--<div class="form-group" style="display: inline-block;width:40%;vertical-align: top">--%>
    <%--<label>真实姓名</label>--%>
    <%--<span>\${real_name}</span>--%>
    <%--</div>--%>
    <%--{{/if}}--%>
    {{if topLevel}}
    <div class="form-group" style="display: inline-block;width:40%;vertical-align: top">
        <label>置顶级别(级别越高显示越靠前)</label>
        <span  class="edit_able" data-name="topLevel" data-id="\${id}">\${topLevel}</span>
    </div>
    {{/if}}
    <div class="form-group" style="display: inline-block;width:40%;vertical-align: top">
        <label>公司名称</label>
        <span class="edit_able" data-name="companyName" data-id="\${id}">\${companyName ||'未配置'}</span>
    </div>
    <div class="form-group" style="display: inline-block;width:40%;vertical-align: top">
        <label>公司简称</label>
        <span class="edit_able" data-name="stName" data-id="\${id}">\${stName||'未配置'}</span>
    </div>
    <div class="form-group" style="display: inline-block;width:40%;vertical-align: top">
        <label>公司法人</label>
        <span class="edit_able" data-name="chairtMan" data-id="\${id}">\${chairtMan ||'未配置'}</span>
    </div>
    {{if userAddressName}}
    <div class="form-group" style="display: inline-block;width:40%;vertical-align: top">
        <label>公司详细地址</label>
        <span class="edit_able" >\${userAdd.detailAddress || '未配置'}</span>
    </div>
    {{/if}}
    <div class="form-group" style="display: inline-block;width:40%;vertical-align: top">
        <label>公司电话</label>
        <span class="edit_able" data-name="userContact" data-id="\${id}">\${userContact ||'未配置'}</span>
    </div>
    <div class="form-group" style="display: inline-block;width:40%;vertical-align: top">
        <label>银行卡号</label>
        <span class="edit_able" data-name="certCard" data-id="\${id}">\${certCard || '未配置'}</span>
    </div>
    <div class="form-group" style="display: inline-block;width:40%;vertical-align: top">
        <label>开户行</label>
        <span class="edit_able" data-name="openBank" data-id="\${id}">\${openBank || '未配置'}</span>
    </div>
    <div class="form-group" style="display: inline-block;width:40%;vertical-align: top">
        <label>手机号码</label>
        <span>\${phone || '未配置'}</span>
    </div>
    <%--{{if majarBus}}--%>
    <%--<div class="form-group">--%>
    <%--<label>主营业务</label>--%>
    <%--<span>\${majarBus}</span>--%>
    <%--</div>--%>
    <%--<hr>--%>
    <%--{{/if}}--%>
    <div class="form-group" style="display: inline-block;width:40%;vertical-align: top">
        <label>营业执照</label>
        <div><img class="decode-img edit_able" data-src="\${busListenerPic ||'${ctx}/resources/ueditor/dialogs/image/images/image.png'}"
                  data-type="img" data-name="busListenerPic" data-id="\${id}" style="cursor: pointer;"/></div>
    </div>
    <div class="form-group" style="display: inline-block;width:40%;vertical-align: top">
        <label>公司LOGO</label>
        <div><img class="decode-img edit_able" data-src="\${userLogo}" data-name="userLogo"
                  data-type="img" data-id="\${id}" style="cursor: pointer;"/></div>
    </div>
    <%--{{if idcard_pics}}--%>
    <%--<div class="form-group" style="display: inline-block;width:40%;vertical-align: top">--%>
    <%--<label>法人身份证</label>--%>
    <%--{{each(i,img) idcard_pics}}--%>
    <%--<span><img class="decode-img" data-src="\${img}" title="点击查看大图"--%>
    <%--style="cursor: pointer;"/></span>--%>
    <%--{{/each}}--%>
    <%--</div>--%>
    <%--{{/if}}--%>


    <hr>
    <div class="form-group">
        <label>场景照片</label>
        <div>
            <img class="decode-img edit_able" data-type="img" data-name="companyPics1" data-id="\${id}" data-src="\${companyPics[0]||'${ctx}/resources/ueditor/dialogs/image/images/image.png'}"   style="cursor: pointer;"/>
            <%--<img class="decode-img edit_able" data-type="img" data-name="companyPics2" data-id="\${id}" data-src="\${companyPics[1]||'${ctx}/resources/ueditor/dialogs/image/images/image.png'}"  style="cursor: pointer;"/>--%>
            <%--<img class="decode-img edit_able" data-type="img" data-name="companyPics3" data-id="\${id}" data-src="\${companyPics[2]||'${ctx}/resources/ueditor/dialogs/image/images/image.png'}"  style="cursor: pointer;"/>--%>
            <%--<img class="decode-img edit_able" data-type="img" data-name="companyPics4" data-id="\${id}" data-src="\${companyPics[3]||'${ctx}/resources/ueditor/dialogs/image/images/image.png'}"   style="cursor: pointer;"/>--%>
        </div>
    </div>

    <div class="form-group" style="display: inline-block;width:40%;vertical-align: top">
        <label>身份证号</label>
        <span class="edit_able" data-name="idCard" data-id="\${id}">\${idCard||'未配置'}</span>
    </div>

    <%--{{if employ_expes}}--%>
    <%--<div class="form-group">--%>
    <%--<label>工作经验</label>--%>
    <%--<span>\${employ_expes}</span>--%>
    <%--</div>--%>
    <%--{{/if}}--%>
    <%--{{if skills}}--%>
    <%--<div class="form-group">--%>
    <%--<label>维修技能</label>--%>
    <%--<span>\${skills}</span>--%>
    <%--</div>--%>
    <%--{{/if}}--%>

    <div class="form-group" style="display: inline-block;width:40%;vertical-align: top">
        <label>身份证正面</label>
        <div><img data-src="\${idCardImg1 ||'${ctx}/resources/ueditor/dialogs/image/images/image.png'} " data-type="img" data-name="idCardImg1" data-id="\${id}" class=" decode-img edit_able"  style="cursor: pointer;"/>
        </div>
    </div>
    <div class="form-group" style="display: inline-block;width:40%;vertical-align: top">
        <label>身份证反面</label>
        <div><img data-src="\${idCardImg2 || '${ctx}/resources/ueditor/dialogs/image/images/image.png'}" data-type="img" data-name="idCardImg2" data-id="\${id}" class="decode-img edit_able"  style="cursor: pointer;"/>
        </div>
    </div>
</script>
<jsp:include page="/WEB-INF/view/admin/shop/content/common-tmpl.jsp"></jsp:include>
<script>
    $(function () {
        loadData();
    })

    function pageLoad() {
        var pageCount = Math.ceil((parseInt(($('#total').val() || 0)) / parseInt($("#pageSize").val() || 10)));
        $("#pagination").pagination({
            pageCount: pageCount,
            pageSize: parseInt($("#pageSize").val() || 10),
            totalCount: parseInt($("#total").val()),
            current: parseInt($("#pageNum").val()),
            jump: true,
            coping: true,
            homePage: '首页',
            endPage: '末页',
            prevContent: '上页',
            nextContent: '下页',
            callback: function (that) {
                //console.log("that:%o", that);
                $("#pageNum").val(that.getCurrent());
                loadData();
                that.setCurrentPage()
            }
        })
    }

    function loadData() {
        var data = {
            pageNum: $("#pageNum").val(),
            pageSize: $("#pageSize").val(),
            startTime: $("#timeRange").val().split(" to ")[0],
            endTime: $("#timeRange").val().split(" to ")[1]
        };
        if (!isEmpty($("#keyword").val())) {
            data["keyword"] = encodeURI($("#keyword").val());
        }

        if ($("#reviewStatus").length >= 1) {
            var reviewStatus = $("#reviewStatus").val();
            data["reviewStatus"] = reviewStatus;
        }

        if ($("#shopId").length >= 1) {
            data["shopId"] = $("#shopId").val();
        }

        asyncAjax({
            url: ctx + "/" +
            "user/mgr/list/${type}?" + $.param(data).replace(/(%5D|%5B)/g, ""),
            type: "post",
            beforeSend: function (req) {
                $("#mainTable tbody").html("<tr><td colspan=\"7\"><div class=\"alert alert-warning\">正在请求数据...</div></td></tr>");
            },
            success: function (res) {
                //console.log("res:%o", res);
                if (res["result"] == "0") {
                    if (res["data"].length <= 0) {
                        $("#mainTable tbody").html("<tr><td colspan=\"7\"><div class=\"alert alert-warning\">没有找到符合条件的数据！</div></td></tr>");
                    } else {
                        $("#total").val(res["total"] || 0);
                        $("#mainTable tbody").html("");
                        $("#dataTmpl").tmpl(res["data"]).appendTo("#mainTable tbody");
                        $(".shop-user").each(function () {
                            getShopUserInfo($(this).attr("data-id"), $(this));
                        })
                        pageLoad();
                    }
                } else {

                }
            }
        })
    }


    function getShopUserInfo(id, el) {
        var data = {};
        asyncAjax({
            url: ctx + "/user/mgr/user/" + id + "?" + $.param(data).replace(/(%5D|%5B)/g, ""),
            data: data,
            success: function (res) {
                //console.log("res:%o", res);
                if (res["result"] == "0") {
                    el.html(res["data"]["nickname"]);
                } else {
                    alert("未找到商户信息!");
                }
            }
        })
    }


    function showAuthInfo(id) {
        var data = {userId: id}
        asyncAjax({
            url: ctx + "/user/mgr/authinfo?" + $.param(data).replace(/(%5D|%5B)/g, ""),
            success: function (res) {
                //console.log("res:%o", res);
                if (res["result"] == "0") {
                    $(".auth-info-box").html("");
                    $("#authInfoTmpl").tmpl(res["data"]).appendTo($(".auth-info-box"));
                    $(".edit_able").clickEditVal(editCallBack);
                    $(".decode-img").each(function () {
                        $(this).attr("src", decodeURIComponent(decodeURIComponent($(this).attr("data-src"))));
                        //console.log("data-src:%o", decodeURIComponent(decodeURIComponent($(this).attr("data-src"))))
                    })
                    $('.auth-dialog').modal('show');
                } else {
                    bootbox.alert("发生错误:" + res["msg"]);
                }
            }
        })
    }
    function editCallBack(data, el) {
        updateinfo(data, el);
    }

    function updateinfo(data, el) {
        var param = {
            id: data["id"],
            name:data["name"],
            src:data["src"],
            value:data["value"]

        };
        updateUserInfoSet(param, function () {
            if (data["type"] == "text" || data["type"] == "time") {
                $(el).text(data["value"]);
            } else if (data["type"] == "img") {
                $(el).attr("src", data["value"]);
            } else if (data["type"] == "good-class") {
                //console.log("update class:%o,el:%o", data, el);
                if (el) {
                    $(el).html(data["value"]);
                }
            }
        })
    }
    function updateUserInfoSet(data, _callback) {
        asyncAjax({
            url: ctx + "/user/mgr/update",
            data:data,
            type: "post",
            success: function (res) {
                //console.log("update good res:%o", res);
                if (res.result == "0" || res.state == "SUCCESS") {
                    bootbox.alert("修改成功");
                    if (typeof _callback == "function") {
                        _callback();
                    }
                }
            }
        })

    }
    function review(id, status, type) {
        if (status == true) {
            bootbox.confirm({
                message: "确定通过该用户的认证申请？",
                callback: function (result) {
                    //console.log("success:%o", result);
                    if (result == true) {
                        var data = {
                            reviewStatus: 2,
                            reviewNotes: "审核通过",
                            userId: id
                        };
                        asyncAjax({
                            url: ctx + "/user/mgr/authinfo/review?" + $.param(data).replace(/(%5D|%5B)/g, ""),
                            success: function (res) {
                                //console.log("res:%o", res);
                                if (res["result"] == "0") {
                                    $("tr[data-id=\"" + id + "\"]").html($("#dataTmpl").tmpl(res["data"]).html());
                                    $(".shop-user").each(function () {
                                        getShopUserInfo($(this).attr("data-id"), $(this));
                                    })
                                    bootbox.alert("操作成功");
                                } else {
                                    bootbox.alert("发生错误:" + res["msg"]);
                                }
                            }
                        })
                    }


                    //     }
                },
                buttons: {
                    confirm: {
                        label: '是',
                        className: 'btn-success',
                    },
                    cancel: {
                        label: '否',
                        className: 'btn-danger'
                    }
                },
            })
        } else {
            bootbox.confirm({
                message: "确定驳回该用户的认证申请？",
                callback: function (confirm) {
                    if (confirm == true) {
                        bootbox.prompt({
                            title: "请填写驳回原因",
                            callback: function (reviewNotes) {
                                if (reviewNotes == null) {
                                    bootbox.alert("取消操作成功！");
                                    return -1;
                                }
                                var data = {
                                    reviewStatus: 3,
                                    reviewNotes: reviewNotes || "无驳回原因，请联系客服人员咨询!",
                                    userId: id
                                };
                                asyncAjax({
                                    url: ctx + "/user/mgr/authinfo/review?" + $.param(data).replace(/(%5D|%5B)/g, ""),
                                    success: function (res) {

                                        if (res["result"] == "0") {
                                            $("tr[data-id=\"" + id + "\"]").html($("#dataTmpl").tmpl(res["data"]).html());
                                            $(".shop-user").each(function () {
                                                getShopUserInfo($(this).attr("data-id"), $(this));
                                            })
                                            bootbox.alert("操作成功");

                                        } else {
                                            bootbox.alert("发生错误:" + res["msg"]);
                                        }
                                    }
                                })
                            },
                            buttons: {
                                confirm: {
                                    label: '确定',
                                    className: 'btn-success'
                                },
                                cancel: {
                                    label: "取消",
                                    className: "btn-danger"
                                }
                            }
                        })
                    }
                },
                buttons: {
                    confirm: {
                        label: '是',
                        className: 'btn-success'
                    },
                    cancel: {
                        label: '否',
                        className: 'btn-danger'
                    }
                },
            })
        }
    }
    function addUser() {
        $('.add-user').modal('show');
    }
    function getfilename() {
        $(".choose-file").on("change", "input[type='file']", function () {
            var filePath = $(this).val();
            if (filePath.indexOf("xlsx") != -1) {
                var arr = filePath.split('\\');
                var fileName = arr[arr.length - 1];
                $(".showFileName").html(fileName);
            } else {
                $(".showFileName").html("");
                bootbox.alert("请选择正确的文件");
                return false
            }
        })
    }
    function upexcel() {
        var filePath = $(".choose-file").val();
        if (isEmpty(filePath)) {
            bootbox.alert("请先选择文件!")
        }
        else {
            var data = {"filepath": filepath};
            asyncAjax({
                url: ctx + "/user/mgr/upexcel?" + $.param(data).replace(/(%5D|%5B)/g, ""),
                error: function (request) {
                    bootbox.alert("上传失败!");
                },
                success: function (data) {
                    bootbox.alert("上传成功!");
                }
            });
        }
    }


    function uploadUserExcel(fileInputId, prviewElementId, hideValueId, type) {
        var file = $("#" + fileInputId);
        var previewElement = $("#" + prviewElementId);
        var val = $("#" + hideValueId);
        if (file == null || file == undefined) {
            alert("文件选择元素ID无效！");
            return;
        }
        if (val == null && val == undefined) {
            alert("返回值存储元素ID无效！");
            return;
        }
        var gp = self.setInterval("getProgress()", 50);
        $.ajaxFileUpload(
            {
                url: '${ctx}/user/upload/upexcel/${type}',
                type: 'post',
                fileElementId: fileInputId,
                dataType: 'application/json',
                async: false,
                success: function (data) {

                    console.info("%o", data);
                    data = JSON.parse(data.match(/{.*}/g)[0]);

                    window.clearInterval(gp);
                    //上传成功返回的信息｛filePath:上传文件后取得的url，result:是否成功，成功为0，失败为-x｝
                    if (data.result == "0") {
                        if (previewElement != null && previewElement != undefined) {
                            previewElement.attr("src", "上传成功");
                        }
                        if (val != null && val != undefined) {
                            val.val("上传成功");
                        }
                    } else {
                        alert(data.msg);
                    }
                    if (typeof callback == "function") {
                        callback();
                    }
                },
                error: function (data, status, e) {
                    alert("上传失败:" + e);
                    window.clearInterval(gp);
                }
            }
        )
    }
    function deleteuser(id) {
        var data ={id:id};
        asyncAjax({
            url: ctx + "/user/mgr/delete?" + $.param(data).replace(/(%5D|%5B)/g, ""),
            success: function (res) {
                //console.log("res:%o", res);
                if (res["result"] == "0") {
                    bootbox.alert("操作成功");
                    loadData();
                } else {
                    bootbox.alert("发生错误:" + res["msg"]);
                }
            }
        })
    }
</script>
</body>
</html>
